-- StartMenu
-- 开始菜单
StartMenu = class()

function StartMenu:init()
    self.mapSizeMenu = MapSizeMenu()
    self.settingMenu = SettingMenu()
    self.creditsMenu = Credits()
    self.playButton = TextButton(WIDTH / 2,HEIGHT / 3 + 70,LP.StartGame)
    self.playButton:setFont("Futura-Medium",44)
    self.playButton.clicked = function() self.mapSizeMenu.show = true end
    self.playButton.backColor = color(0,0,0,0)
    self.playButton.textColor = color(255,255,255,255)
    self.playButton.pressedTextColor = color(189, 189, 189, 160)
    
    self.settingButton = TextButton(WIDTH / 2,HEIGHT / 3 - 40,LP.Setting)
    self.settingButton:setFont("Futura-Medium",44)
    self.settingButton.clicked = function() self.settingMenu.show = true end
    self.settingButton.backColor = color(0,0,0,0)
    self.settingButton.textColor = color(255,255,255,255)
    self.settingButton.pressedTextColor = color(189, 189, 189, 160)
    
    self.codeaInfo = ImageButton(WIDTH - 100,25,"Project:MadeWithCodea")
    self.codeaInfo.width = 180
    self.codeaInfo.color = color(255, 255, 255, 152)
    self.codeaInfo.pressedColor = color(255, 255, 255, 152)
    
    self.credits = TextButton(1,3,LP.Credits)
    self.credits.posMode = UIConst.PosMode.Corner
    self.credits:setFont("SourceSansPro-Regular",30)
    self.credits.textColor = color(255, 255, 255, 140)
    self.credits.pressedTextColor = color(189, 189, 189, 160)
    self.credits.clicked = function()
        self.creditsMenu:show()
    end
    
    self.backGround = "Project:TCBackGround" ..math.random(1,2)
    setupYellowText()
    self.size = 0
    self.index = math.random(1,#YellowText)
    self.splashAlpha = 255
    
    tween.sequence(tween.delay(1),tween(1,self,{splashAlpha = 0},tween.easing.cubicOut))
end

function StartMenu:draw()  
    spriteMode(CENTER)
    
    if self.creditsMenu.showing then
        self.creditsMenu:draw()
        return
    elseif self.mapSizeMenu.show then
        tint(173, 173, 173, 255)
        sprite(self.backGround,WIDTH / 2,HEIGHT / 2,WIDTH)
        self.mapSizeMenu:draw()
        return
    elseif self.settingMenu.show then
        tint(170, 170, 170, 255)
        sprite(self.backGround,WIDTH / 2,HEIGHT / 2,WIDTH)
        self.settingMenu:draw()
        return
    end
    
    tint(255, 255, 255, 255)
    sprite(self.backGround,WIDTH / 2,HEIGHT / 2,WIDTH,HEIGHT)

    sprite("Project:TCLogoWhite",WIDTH / 2,HEIGHT / 2 * 1.6,WIDTH / 1.3)
    spriteMode(CORNER)
    
    --[[
    textMode(CORNER)
    font("Futura-Medium")
    fontSize(15)
    fill(194, 213, 217, 184 * (0.75 + 0.25 * math.sin(ElapsedTime)))
    text(LP.Developer,0,0)
      ]]
    font("HelveticaNeue")
    fontSize(20)
    fill(0, 0, 0, 165)
    textMode(CENTER)
    text(LP.Version,WIDTH / 2,12)
    
    pushMatrix()
    pushStyle()
    resetMatrix()
    strokeWidth(5)
    fontSize(40 + math.sin(ElapsedTime * 3) * 4)
    translate(WIDTH - 220,HEIGHT - 200)
    rotate(25)
    
    fill(143, 143, 143, 255)
    text(YellowText[self.index],-2,-2)
    fill(255, 242, 0, 255)
    text(YellowText[self.index],0,0)
    popStyle()
    popMatrix()
    
    self.playButton:draw()
    self.settingButton:draw()
    self.codeaInfo:draw()
    self.credits:draw()
    self.creditsMenu:draw()
    
    tint(255, 255, 255, self.splashAlpha)
    sprite("Project:TC Studio Icon",0,0,WIDTH,HEIGHT)
end

function StartMenu:touched(touch)
    if self.mapSizeMenu.show then
        self.mapSizeMenu:touched(touch)
        return
    elseif self.settingMenu.show then
        self.settingMenu:touched(touch)
        return
    elseif self.creditsMenu.showing or self.creditsMenu.appearing then
        self.creditsMenu:touched(touch)
        return
    end
    
    self.playButton:touched(touch)
    self.settingButton:touched(touch)
    self.codeaInfo:touched(touch)
    self.credits:touched(touch)
end
